$(document).ready(function() {
      // Add custom class to pagination div
      $.fn.dataTableExt.oStdClasses.sPaging = 'dataTables_paginate paging_bootstrap paging_custom';

      $('div.dataTables_filter input').addClass('form-control');
      $('div.dataTables_length select').addClass('form-control');

      /*************************************************/
      /**************** BASIC DATATABLE ****************/
      /*************************************************/

      /* Define two custom functions (asc and desc) for string sorting */
      jQuery.fn.dataTableExt.oSort['string-case-asc']  = function(x,y) {
          return ((x < y) ? -1 : ((x > y) ?  1 : 0));
      };
       
      jQuery.fn.dataTableExt.oSort['string-case-desc'] = function(x,y) {
          return ((x < y) ?  1 : ((x > y) ? -1 : 0));
      };

      /* Add a click handler to the rows - this could be used as a callback */
      $("#tabel tbody tr").click( function( e ) {
        if ( $(this).hasClass('row_selected') ) {
          $(this).removeClass('row_selected');
        }
        else {
          oTable01.$('tr.row_selected').removeClass('row_selected');
          $(this).addClass('row_selected');
        }

        // FadeIn/Out delete rows button
        if ($('#tabel tr.row_selected').length > 0) {
          $('#deleteRow').stop().fadeIn(300);
        } else {
          $('#deleteRow').stop().fadeOut(300);
        }
      });
      
      var oTable01 = $('#tabel').DataTable({
      	"bServerSide": true,
      	"bAutoWidth": true,
      	"bStateSave": true,
      	"bPaginate": true, // 是否使用分页
      	"bProcessing": true, //是否显示正在处理的提示 
      	"bLengthChange": true, //是否启用设置每页显示记录数 
      	"bFilter": true, //是否使用搜索 
      	"bJQueryUI": true, //页面风格使用jQuery.
      	"sServerMethod":"POST",
          "bDestroy": true,
          "sScrollXInner": "100%",
          "bScrollCollapse": true,
          "sPaginationType": "bootstrap",
          "sAjaxSource":"/admin/admin/getData",
          "aoColumns": [
              { "mDataProp": "name" },
              { "mDataProp": "realname"},
              { "mDataProp": "wxname"},
              { "mDataProp": "phone"},
              { "mDataProp": "loginIp"},
              { "mDataProp": "enabled"},
              { "mDataProp": "id", "sClass": "col-md-2 control text-center"}
            ],
           "aoColumnDefs":[
                {"aTargets":[6],"mRender":function(data,type,full){
                		return "<a href='/admin/admin/edit/"+ data +"' class='btn btn-blue'>修改</a>  "
                		+"<a href='/admin/admin/delete/"+ data +"' class='btn btn-red'>删除</a>"
                	}
                }          
           ], 
          "bAutoWidth": true, //列的宽度会根据table的宽度自适应
          "aaSorting": [[0, "desc"]],
          "aLengthMenu": [
              [5, 10, 20],
              [5, 10, 20] // change per page values here
          ],
          "iDisplayLength": 5,
          "sDom": "<'row'<'col-lg-6'l><'col-lg-6'f>r>t<'row'<'col-lg-6'i><'col-lg-6'p>>",
          "oLanguage": {
          	"sProcessing" : "正在加载中......",
              "sLengthMenu" : "每页显示 _MENU_ 条记录",
              "sZeroRecords" : "正在加载中......",
              "sEmptyTable" : "表中无数据存在！",
              "sInfo" : "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
              "sInfoEmpty" : "显示0到0条记录",
              "sInfoFiltered" : "数据表中共为 _MAX_ 条记录",
              "sSearch" : "",
              "oPaginate": {
              	"sFirst" : "首页",
                  "sPrevious": "上一页",
                  "sNext": "下一页",
              	 "sLast" : "末页"
              }
          },
          "fnInitComplete": function(oSettings, json) { 
              $('.dataTables_filter input').attr("placeholder", "输入查询条件");
            }
      });
      
      var addRowLink = '<a href="/admin/add" id="addRow" class="btn btn-blue btn-xs add-row">添加管理员</a>'
      $('#basicDataTable_wrapper').append(addRowLink);
      
      function fnGetSelected(oTable01Local){
        return oTable01Local.$('tr.row_selected');
      };

      //initialize chosen
      $('.dataTables_length select').chosen({disable_search_threshold: 10});

      // Add custom class
      $('div.dataTables_filter input').addClass('form-control');
      $('div.dataTables_length select').addClass('form-control');
});